package com.boot.mall.product.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.Query;

import com.boot.mall.product.dao.AttrDao;
import com.boot.mall.product.entity.AttrEntity;
import com.boot.mall.product.service.AttrService;


@Service("attrService")
public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements AttrService {

    // 根据分类id分页查询   销售属性
    @Override
    public PageUtils pageQueryByCategoryId(Map<String, Object> params, String categoryId) {
        // 获取参数
        String curr = (String) params.get("page");
        long current = 1;
        if (curr != null) {
            current = Integer.parseInt(curr);
        }
        long limit = 1;
        String limitStr = (String) params.get("limit");
        if (limitStr != null) {
            limit = Integer.parseInt(limitStr);
        }
        // 创建分页对象
        Page<AttrEntity> page = new Page<>(current,limit);
        // 执行查询
        baseMapper.selectPage(page,
                new QueryWrapper<AttrEntity>().eq("catelog_id",categoryId).eq("attr_type",0));
        // 结果封装
        PageUtils pageUtils = new PageUtils(page.getRecords(),(int)page.getTotal(),(int)page.getSize(),(int)current);
        return pageUtils;

    }

    @Override
    public List<Long> selectSearchAttrs(List<Long> attrIds) {
        return baseMapper.selectSearchAttrs(attrIds);
    }
}